package com.quanquan.store.repository;

import com.quanquan.store.entity.CouponHistory;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @ClassName:HistoryCouponRepository
 * @Description:TODO
 * @Author:xiongjunbao
 * @Date:2019/3/28 15:23
 * @Version 1.0
 */
public interface CouponHistoryRepository extends JpaRepository<CouponHistory, String> {

    @Query(value = "select * from oo_coupon_history where status_show = 0 and status_remove = 0 and user_id = ?1 order by update_time desc limit ?2,?3", nativeQuery = true)
    List<CouponHistory> findByUserId(String userId, Integer count, Integer size);

    @Query(value = "select * from oo_coupon_history where status_show = 0 and status_remove = 0 and user_id = ?1 order by update_time desc", nativeQuery = true)
    List<CouponHistory> findByUserId(String userId);

    @Query(value = "select * from oo_coupon_history where status_show = 0 and status_remove = 0 and user_id = ?1 and coupon_id = ?2", nativeQuery = true)
    CouponHistory queryByUserIdAndCouponId(String userId, String couponId);

}
